/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bullionxpress.client.view;

import com.bullionxpress.client.application.ClientGlobals;
import com.bullionxpress.shared.model.Instrument;
import com.bullionxpress.shared.model.Tick;
import com.bullionxpress.shared.util.Log;
import java.util.Calendar;
import java.util.Date;

public class ChartDataLoader extends Thread implements Runnable {

    //ProgressDialog dialog = null;
    public ChartDataLoader()
    {
        //this.dialog = dialog;
    }

    volatile boolean complete = false;
    public boolean isComplete()
    {
        return complete;
    }
    
    public void run() {
        try {
            Log.info("Running timer...");
            Calendar c = Calendar.getInstance();
            c.add(Calendar.DATE, -5);
            Date _d = c.getTime();
            ClientGlobals.chartView.clearData();
            Tick[] list = ClientGlobals.chartService.getHistory(ClientGlobals.instrument, _d);
            Log.info("Adding to chart:" + list.length);
            for (int i = 0; i < list.length; i++) {
                Tick t = list[i];
                ClientGlobals.chartView.add(t);
            }
            ClientGlobals.chartView.setInstrument(ClientGlobals.instrument, ClientGlobals.chartView.getVisibleList());
            ClientGlobals.scrollBarPanel.getScrollBar().setValue(list.length);
            Log.info("Finished adding to chart");
            complete = true;
        } catch (Exception ex) {
            ex.printStackTrace();
            complete = true;
        }

        Log.info("Task complete");
    }
};
